<!DOCTYPE html>
<html ng-app="oppia">
  <head>
    <title>Oppia Admin Panel</title>

    {% include 'header_js_libs.html' %}
    <script>
      var oppia = angular.module('oppia', []);
      oppia.config(function($interpolateProvider) {
        $interpolateProvider.startSymbol('<[');
        $interpolateProvider.endSymbol(']>');
      });

      function Admin($scope, $http) {
        $scope.message = '';

        $scope.reload = function(item) {
          $scope.message = 'Processing...';
          var request = $.param({payload: JSON.stringify(
              {action: 'reload', item: item})}, true);

          $http.post(
            '/admin',
            request,
            {headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).
          success(function(data) {
              $scope.message = 'Data reloaded successfully. Please remember to flush memcache so that users do not see stale values.';
            }).error(function(errorResponse) {
              $scope.message = 'Server error: ' + errorResponse.error;
            });
        };
      };
    </script>
  </head>

  <body ng-controller="Admin">
    <button ng-click="reload('widgets')">
      Reload widgets
    </button>
    <br><br>
    <button ng-click="reload('explorations')">
      Reload explorations
    </button>
    <br><br>
    <[message]>
  </body>
</html>
